<?php

namespace App\Http\Resources;

use App\Model\Repository\ApiRepository;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * Class ApiResource
 * @package App\Http\Resources
 */
class ApiResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        /* @var ApiRepository $this */
        return [
            'api_name' => $this->getApiName(),
            'remark' => $this->getRemark(),
            'domain' => $this->getDomain(),
            'path' => $this->getPath(),
            'version' => $this->getVersion(),
            'method' => $this->getMethod(),
            'content_type' => $this->getContentType(),
            'category_id' => $this->getCategoryId(),
            'project_id' => $this->getProjectId(),
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'request' => $this->request,
            'response' => [
                'content_type' => $this->response->getContentType(),
                'body' => $this->response->getBodyHtml(),
                'demo' => $this->response->getDemoHtml(),
            ],
            'request_url' => $this->getRequestUrl(),
        ];
    }
}
